package reflect;

import java.util.Scanner;

public class ReflectDemo2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        Person p = new Person();
        System.out.println(p);
        System.out.println("------");

        Scanner sc = new Scanner(System.in);
        while (true) {
            System.out.println("请输入完整类名：");
            String s = sc.nextLine();
            // 加载需要实例化对象的类的类对象
            Class cls = Class.forName(s);
            // 类对象类对象提供了方法：newInstance
            Object o = cls.newInstance();
            System.out.println(o);

        }
    }
}
